package defectsim.material;

import javax.vecmath.Vector3d;


public class MaterialFactory {
	
	public enum MaterialName {
		Copper,
		Iron,
		Aluminum
	}
	
	public static Material createMaterial(MaterialName mName, int activeSlip){
		Material material;
		SlipSystem[] slipSystems; 
		switch(mName){
		case Copper:
			material = new Material("Copper");
			material.setBurgersVector(0.255);
			material.setDampingCoefficientForGlide(5.0e-5);
			material.setDampingCoefficientForClimb(5.0e-5); //TODO write the correct value for climb
			material.setPoissonRatio(0.324);
			material.setShearModulus(42);
			material.setNucleationStress(0.004);
			material.setNucleationTime(4.0e-6);
			material.setSlipPlaneSpacing(100);
			material.setActivationEnergyAtZero(0.05);
			material.setConstantVelocity(1600.0);
			material.setEffectiveStressAtZero(2.62);
			material.setCrystalSystem(Material.CrystalSystems.FCC);
			material.setNumberOfSlipSystems(3);
			slipSystems = new SlipSystem[material.getNumberOfSlipSystems()];
			switch(activeSlip){
			case 1:
				slipSystems[0] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(1.0, 1.0, 0.0), true, 0.0);
				slipSystems[1] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(1.0, 0.0, 1.0), false, 60.0);
				slipSystems[2] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(0.0, 1.0, 1.0), false, 120.0);
				break;
			case 2:
				slipSystems[2] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(1.0, 1.0, 0.0), true, 0.0);
				slipSystems[0] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(1.0, 0.0, 1.0), false, 60.0);
				slipSystems[1] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(0.0, 1.0, 1.0), false, 120.0);
				break;
			}
			material.setSlipSystems(slipSystems);
			material.setNumberOfActiveSlipSystems(activeSlip);
			return material;
		case Aluminum:
			material = new Material("Aluminum");
			material.setBurgersVector(0.238);
			material.setDampingCoefficientForGlide(5.0e-4);
			material.setDampingCoefficientForClimb(5.0e-4); //TODO write the correct value for climb
			material.setPoissonRatio(0.35);
			material.setShearModulus(26);
			material.setNucleationStress(0.004);
			material.setNucleationTime(4.0e-6);
			material.setSlipPlaneSpacing(100);
			material.setCrystalSystem(Material.CrystalSystems.FCC);
			material.setActivationEnergyAtZero(0.1);
			material.setConstantVelocity(1600.0);
			material.setEffectiveStressAtZero(2.62);
			material.setNumberOfSlipSystems(3);
			slipSystems = new SlipSystem[material.getNumberOfSlipSystems()];
			switch(activeSlip){
			case 1:
				slipSystems[0] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(1.0, 1.0, 0.0), true, 0.0);
				slipSystems[1] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(1.0, 0.0, 1.0), false, 60.0);
				slipSystems[2] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(0.0, 1.0, 1.0), false, 120.0);
				break;
			case 2:
				slipSystems[2] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(1.0, 1.0, 0.0), true, 0.0);
				slipSystems[0] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(1.0, 0.0, 1.0), false, 60.0);
				slipSystems[1] = new SlipSystem(new Vector3d(-1.0, 1.0, 1.0), new Vector3d(0.0, 1.0, 1.0), false, 120.0);
				break;
			}
			material.setSlipSystems(slipSystems);
			material.setNumberOfActiveSlipSystems(activeSlip);
			return material;
		}
		throw new IllegalArgumentException("The material name " + mName + " is not recognized.");
	}
}
